$(function () {
    //初始化页面列表
    var bar_dialog = $("#bar_dialog");
    var pic_dialog = $("#pic_dialog");
    $("#accidentChart_datagrid").datagrid({
        fit: true,
        url: "/accidentChart/list",
        fitColumns: true,
        striped: true,
        pagination: true,
        singleSelect: true,
        checkOnSelect: true,
        rownumbers: true,
        toolbar: "#tb",
        columns: [[
            {field: 'id', title: '编号', hidden: true},
            {
                field: 'groupByType', title: '分组类型', align: 'center', width: 100, formatter: function (value, row) {
                return "<p>" + row.groupByType + "</p>"
            }
            },
            {field: 'totalCompensation', title: '赔偿总额', align: 'center', width: 100}
        ]]
    })
    //初始化页面列表--end


    /*柱状图信息的弹窗*/
    bar_dialog.dialog({
        width: 600,
        height: 480,
        closed: true,
        modal: true,
        buttons: '#bar_btn'
        /* onClose: function () {
         }*/
    });
    /*柱状图信息的弹窗*/
    pic_dialog.dialog({
        width: 600,
        height: 480,
        closed: true,
        modal: true,
        buttons: '#pic_btn',
        onClose: function () {
        }
    });


    //统一事件绑定
    $("a[data-cmd]").click(function () {
        var methodName = $(this).data("cmd");
        methodObj[methodName]();
    });
    //统一事件管理
    var methodObj = {
        query: function () {
            //获取输入框值
            var groupByType = $("#groupByType option:selected").val();
            sale_datagrid.datagrid('load', {
                groupByType: groupByType
            })
        },
        bar: function () {
            var groupByType = $("#groupByType option:selected").val();
            $("#barTable").prop("src", "/accidentChart/queryByBar?groupByType=" + groupByType);
            bar_dialog.dialog('open');
            bar_dialog.dialog('setTitle', '销售报表');
        },
        pic: function () {
            var groupByType = $("#groupByType option:selected").val();
            $("#picTable").prop("src", "/accidentChart/queryByPic?groupByType=" + groupByType);
            pic_dialog.dialog('open');
            pic_dialog.dialog('setTitle', '销售报表');
        },
        cancelBar: function () {
            bar_dialog.dialog('close');
        },
        cancelPic: function () {
            pic_dialog.dialog('close');
        }

    };


})
function btn_search() {
    var group = $("#groupByType").combobox("getValue")
    var beginTime = $("#beginTime").datebox("getValue")
    var endTime = $("#beginTime").datebox("getValue")
    $("#accidentChart_datagrid").datagrid("load", {
        groupByType: group,
        beginDate: beginTime,
        endDate: endTime
    })
}






